//
//  MyViewController.swift
//  二次源
//
//  Created by 李建文 on 2016/10/16.
//  Copyright © 2016年 二次源. All rights reserved.
//

import UIKit

class MyViewController: UIViewController {
    
    @IBOutlet weak var name: UILabel!
    
    @IBOutlet weak var loginButton: UIButton!
    
    @IBOutlet weak var headImage: UIImageView!
    
    let db:dbController = dbController()

    override func viewDidLoad() {
        super.viewDidLoad()
        headImage.layer.masksToBounds = true
        headImage.layer.cornerRadius = UIScreen.main.bounds.height * 0.25 * 0.18 * 1.55
        let temp = db.getUserName()
        if(temp==""){
            let alertController = UIAlertController(title: "系统提示",
                                                    message: "您尚未登录", preferredStyle: .alert)
            let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
            let okAction = UIAlertAction(title: "登录", style: .default, handler: {
                action in
                    self.didLogin(self.loginButton)
                
            })
            alertController.addAction(cancelAction)
            alertController.addAction(okAction)
            self.present(alertController, animated: true, completion: nil)
        }else{
            self.name.text = temp
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func didLogin(_ sender: AnyObject) {
        print("登录")
        self.performSegue(withIdentifier: "login", sender: nil)
    }

    @IBAction func didAddAddress(_ sender: AnyObject) {
        print("点击添加地址")
    }
    
    @IBAction func didRe(_ sender: AnyObject) {
        db.deleAll()
        self.name.text = "请登陆"
    }
    
    override func viewDidAppear(_ animated: Bool) {
        viewDidLoad()
    }

}
